#ifndef PUDGE_UI_BUTTON_TEST_HPP
#define PUDGE_UI_BUTTON_TEST_HPP

#include <pudge/ui/button.hpp>
#include <pudge/grfx/mesh.hpp>
#include <pudge/grfx/render.hpp>
#include <pudge/grfx/image.hpp>
#include <pudge/grfx/texture.hpp>

namespace pudge { namespace ui {

	struct button_test_0
	{
		

		template<class Context> void operator()(Context & con)
		{
			typedef pudge::ui::button<Context> Button;
			typedef Button::sprite_type Sprite;

			using pudge::meta::_1;
			using pudge::meta::_2;

			// load texture from file and cache in texture memory

			pudge::grfx::image<pudge::grfx::color<pudge::grfx::RGBA,unsigned char>> img("../../../media/button.png");
			pudge::grfx::texture2d<texture_traits> tex(img.width(), img.height(), img.colors());

			// create a button

			Button button_;
			button_.up = Sprite(0.0f, 0.0f, (float)tex.width(), (float)tex.height());
			button_.down = Sprite((float)tex.width(), (float)tex.height(), 0.0f, 0.0f);
			button_.hover = Sprite(0.0f, (float)tex.width(), 0.0f, (float)tex.height());
			button_.coords = button_.up;

			// NOTE: ticking a button results in a cache operation that will be decached when the button is destroyed.

			button_.tick() += tick_button(_1, _2, ref(button_));
			button_.draw() += draw_button(_1, ref(button_), ref(tex));

			button_.tick()(con, Context::ui_frame_type(0,500,100,600));

			con.sprite_shader().use(con);
			button_.draw()(con);
		}
	};

	template<class Context> void button_test(Context & c)
	{
		button_test_0()(c);
	}
}}

#endif